package com.ytd.smartcanteen.weighting.dao;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.Update;

import com.ytd.smartcanteen.weighting.bean.OrderBean;

import java.util.List;

/**
 * 餐品表
 *
 * @author gaoguanchao
 * @since 2023/3/24
 */
@Dao
public interface OrderBeanDao {

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insert(OrderBean orderBean);

    @Update
    void update(OrderBean orderBean);

    @Delete
    void delete(OrderBean orderBean);

    @Query("DELETE FROM orderbean")
    void deleteAll();

    @Query("SELECT * FROM orderbean")
    List<OrderBean> getAll();

    @Query("SELECT * FROM orderbean WHERE mealTimeId !=:mealTimeId")
    List<OrderBean> getLocalOrder(String mealTimeId);

    @Query("SELECT count(*) FROM orderbean WHERE mealTimeId !=:mealTimeId")
    int getLocalOrderCount(String mealTimeId);

    @Query("SELECT * FROM orderbean WHERE mealTimeId !=:mealTimeId limit :start,:pageSize")
    List<OrderBean> getLocalOrderLimit(String mealTimeId, int start, int pageSize);

    @Query("DELETE FROM orderbean WHERE uploadState = 1")
    void deleteUploadData();

    @Query("SELECT count(*) FROM orderbean WHERE mealTimeId !=:mealTimeId AND uploadState = 1")
    int getLocalOrderUploadedCount(String mealTimeId);
}
